package cn.glinks.liuhe.utils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import cn.glinks.liuhe.R;


/**
 * Activity转换动画工具类
 *
 * @author MarsBlade of Cyh
 * @created 2017-03-03 12:30
 */

public class ActTransAnimUtils {
    /**
     * Activity启动跳转(带过渡动画)
     * @param from 发起启动的Activity对象
     * @param to 响应启动的Activity类
     * @param enterAnim the incoming activity的进入动画
     * @param exitAnim the outgoing activity的退出动画
     * @param bundle 需要携带的数据
     */
    public static void startAction(Activity from, Class<?> to, int enterAnim, int exitAnim, Bundle bundle) {
        Intent intent = new Intent(from, to);
        if (bundle != null){
            intent.putExtras(bundle);
        }
        from.startActivity(intent);
        from.overridePendingTransition(enterAnim, exitAnim);
    }

    public static void startActionFadeInFadeOut(Activity from, Class<?> to, Bundle bundle) {
        startAction(from, to, R.anim.act_fade_in, R.anim.act_fade_out, bundle);
    }

    public static void startActionPushUp(Activity from, Class<?> to, Bundle bundle) {
        startAction(from, to, R.anim.act_push_bottom_in, R.anim.act_push_top_out, bundle);
    }

    public static void startActionPushDown(Activity from, Class<?> to, Bundle bundle) {
        startAction(from, to, R.anim.act_push_top_in, R.anim.act_push_bottom_out, bundle);
    }

    public static void startActionSlideLeftToRight(Activity from, Class<?> to, Bundle bundle) {
        startAction(from, to, R.anim.act_slide_in_from_left, R.anim.act_slide_out_to_right, bundle);
    }

    public static void startActionSlideRightToLeft(Activity from, Class<?> to, Bundle bundle) {
        startAction(from, to, R.anim.act_slide_in_from_right, R.anim.act_slide_out_to_left, bundle);
    }

    public static void startActionFadeInFadeOut(Activity from, Class<?> to) {
        startAction(from, to, R.anim.act_fade_in, R.anim.act_fade_out, null);
    }

    public static void startActionPushUp(Activity from, Class<?> to) {
        startAction(from, to, R.anim.act_push_bottom_in, R.anim.act_push_top_out, null);
    }

    public static void startActionPushDown(Activity from, Class<?> to) {
        startAction(from, to, R.anim.act_push_top_in, R.anim.act_push_bottom_out, null);
    }

    public static void startActionSlideLeftToRight(Activity from, Class<?> to) {
        startAction(from, to, R.anim.act_slide_in_from_left, R.anim.act_slide_out_to_right, null);
    }

    public static void startActionSlideRightToLeft(Activity from, Class<?> to) {
        startAction(from, to, R.anim.act_slide_in_from_right, R.anim.act_slide_out_to_left, null);
    }


    /**
     * Activity结束跳转(带过渡动画)
     * @param from 要结束的Activity对象
     * @param enterAnim the incoming activity的进入动画
     * @param exitAnim the outgoing activity的退出动画
     */
    public static void finishAction(Activity from, int enterAnim, int exitAnim) {
        from.finish();
        from.overridePendingTransition(enterAnim, exitAnim);
    }

    public static void finishActionPushUp(Activity from) {
        finishAction(from, R.anim.act_push_bottom_in, R.anim.act_push_top_out);
    }

    public static void finishActionPushDown(Activity from) {
        finishAction(from, R.anim.act_push_top_in, R.anim.act_push_bottom_out);
    }

    public static void finishActionSlideLeftToRight(Activity from) {
        finishAction(from, R.anim.act_slide_in_from_left, R.anim.act_slide_out_to_right);
    }

    public static void finishActionSlideRightToLeft(Activity from) {
        finishAction(from, R.anim.act_slide_in_from_right, R.anim.act_slide_out_to_left);
    }

    public static void finishActionFadeInFadeOut(Activity from) {
        finishAction(from, R.anim.act_fade_in, R.anim.act_fade_out);
    }

    public static void finishActionFadeOut(Activity from) {
        finishAction(from, 0, R.anim.act_fade_out);
    }

}
